/////////////////////////////////////////////////////////////////////////////
// 2023 -
//open source under Apache License Version 2.0
/////////////////////////////////////////////////////////////////////////////
//  Modifications by Kumo Inc.
// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//


#pragma once

#include <cctype>
#include <sstream>

namespace Hdfs {

namespace Internal {

class ECPolicy {
public:
    ECPolicy() = default;
    ECPolicy(int8_t id, int32_t cellSize, int32_t dataUnits,
        int32_t parityUnits, const char * codecName) : 
        id(id), cellSize(cellSize), dataUnits(dataUnits), 
        parityUnits(parityUnits), codecName(codecName) {
        name = codecName + 
               std::string("-") + std::to_string(dataUnits) + 
               std::string("-") + std::to_string(parityUnits) + 
               std::string("-") + std::to_string(cellSize / 1024) + "k";
    }

    ~ECPolicy() = default;
    
    const char * getName() const {
        return name.c_str();
    }

    void setName(const char * name_) {
        name = name_;
    }

    int32_t getCellSize() const {
        return cellSize;
    }

    void setCellSize(int32_t cellSize_) {
        cellSize = cellSize_;
    }

    const char * getCodecName() const {
        return codecName.c_str();
    }

    void setCodecName(const char * codecName_) {
        codecName = codecName_;
    }

    int32_t getNumDataUnits() const {
        return dataUnits;
    }

    void setNumDataUnits(int32_t dataUnits_) {
        dataUnits = dataUnits_;
    }

    int32_t getNumParityUnits() const {
        return parityUnits;
    }

    void setNumParityUnits(int32_t parityUnits_) {
        parityUnits = parityUnits_;
    }

    int8_t getId() const {
        return id;
    }

    void setId(int8_t id_) {
        id = id_;
    }

private:
    int8_t id;
    int32_t cellSize;
    int32_t dataUnits;
    int32_t parityUnits;
    std::string name;
    std::string codecName;
};

}
}
